package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.mapper.PermissionMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashSet;
import java.util.List;

@Slf4j
@Service
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;
    @Override
@Transactional
    public void insert(Permission dept) {
        permissionMapper.insert(dept);
    }
    @Transactional
    @Override
    public void update(Permission dept) {
     permissionMapper.update(dept);
    }
    @Transactional
    @Override
    public void delete(Long id) {
permissionMapper.delete(id);
    }
    @Transactional
    @Override
    public Permission selectOne(Long id) {

        return permissionMapper.selectForId(id);
    }
    @Transactional
    @Override
    public List<Permission> selectList() {
        return permissionMapper.selectList();
    }
    @Transactional
    @Override
    public PageInfo<Permission> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
            List<Permission> list = permissionMapper.selectForList(qo);
            return new PageInfo(list);
        }

    @Override
    public void batchSave(LinkedHashSet<Permission> permissionSet) {
        permissionMapper.batchSave(permissionSet);
    }

    @Override
    public List<Permission> queryByRoleId(Long roleId) {
        return permissionMapper.selectByRoleId(roleId);
    }

    @Override
    public List<String> queryExpressionsByEmployeeId(Long employeeId) {
        return permissionMapper.selectExpressionByEmployeeId(employeeId);
    }
}